import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _ModalContainer from "choerodon-ui/pro/lib/modal-container";
import React, { useEffect, useState } from 'react';
import { routerRedux, Switch, Route, withRouter } from 'dva/router';
import ModalContainer, { registerContainer } from "./components/Modal/ModalContainer";
import Authorized from "./components/Authorized/WrapAuthorized";
import PermissionProvider from "./components/Permission/PermissionProvider";
import LocalProviderAsync from "./utils/intl/LocaleProviderAsync";
import { dynamicWrapper } from "./utils/router";
import { inject } from 'what-di';
import DefaultContainer from "./utils/iocUtils/DefaultContainer";
import { initIoc } from "./utils/iocUtils";
import { UedProvider } from "./utils/iocUtils/UedProvider"; // 初始化ioc容器

initIoc();
var WithRouterC7nModalContainer = withRouter(_ModalContainer);
var ConnectedRouter = routerRedux.ConnectedRouter;
var DefaultAuthorizedRoute = Authorized.DefaultAuthorizedRoute,
    PubAuthorizedRoute = Authorized.PubAuthorizedRoute;

function RouterConfig(_ref) {
  var history = _ref.history,
      app = _ref.app;

  var _useState = useState({
    Container: DefaultContainer
  }),
      _useState2 = _slicedToArray(_useState, 2),
      uedConfig = _useState2[0],
      setUedConfig = _useState2[1];

  var Layout = dynamicWrapper(app, ['user', 'login'], function () {
    return import("./layouts/Layout");
  });
  var PubLayout = dynamicWrapper(app, ['user', 'login'], function () {
    return import("./layouts/PubLayout");
  }); // 免登陆无权限路由

  var PublicLayout = dynamicWrapper(app, [], function () {
    return import("./layouts/PublicLayout");
  }); // 免登陆权限路由

  var PrivateLayout = dynamicWrapper(app, [], function () {
    return import("./layouts/PrivateLayout");
  });
  useEffect(function () {
    var ued = inject(UedProvider);
    ued.subscribe(function (_ref2) {
      var _ref2$Container = _ref2.Container,
          Container = _ref2$Container === void 0 ? null : _ref2$Container;
      setUedConfig({
        Container: Container || DefaultContainer
      });
    });
  }, []);
  return /*#__PURE__*/React.createElement(uedConfig.Container, {
    defaultTheme: "theme2"
  }, /*#__PURE__*/React.createElement(LocalProviderAsync, null, /*#__PURE__*/React.createElement(PermissionProvider, null, /*#__PURE__*/React.createElement(ConnectedRouter, {
    history: history
  }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ModalContainer, {
    ref: registerContainer
  }), /*#__PURE__*/React.createElement(WithRouterC7nModalContainer, null), /*#__PURE__*/React.createElement(Switch, null, /*#__PURE__*/React.createElement(Route, {
    path: "/private",
    render: function render(props) {
      return /*#__PURE__*/React.createElement(PrivateLayout, props);
    }
  }), /*#__PURE__*/React.createElement(Route, {
    path: "/public",
    render: function render(props) {
      return /*#__PURE__*/React.createElement(PublicLayout, props);
    }
  }), /*#__PURE__*/React.createElement(PubAuthorizedRoute, {
    path: "/pub",
    render: function render(props) {
      return /*#__PURE__*/React.createElement(PubLayout, props);
    }
  }), /*#__PURE__*/React.createElement(DefaultAuthorizedRoute, {
    path: "/",
    render: function render(props) {
      return /*#__PURE__*/React.createElement(Layout, props);
    }
  })))))));
}

export default RouterConfig;